<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<c:if test="${sessionScope.admin==null }" >
<meta http-equiv="refresh" content="0;url=admin_login.jsp">
</c:if> 
<title>活动分组</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="Dialog.js"></script>
<script type="text/javascript">
var xmlHttp = false;

function sendRequest(method, url, async, callback) {
    if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
       // xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        var msxmls = ["MSXML3" , "MSXML2" , "Microsoft"];
        for(var i=0; i < msxmls.length; i++)
        {
        	try
        	{
        		xmlHttp = new ActiveXObject(msxmls[i]+".XMLHTTP");
        	}
        	catch(e)
        	{
        		//alert("您的浏览器不支持XMLHTTP控件");
        	}
        }
    }
    if (!xmlHttp) {
    	Dialog.alert("错误");
    } else {
        xmlHttp.open(method, url, async);
        xmlHttp.onreadystatechange = callback;
        xmlHttp.send();
    }
}
function callback(){
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var str = xmlHttp.responseText;
        var obj = eval("(" + str + ")");
        Dialog.alert(obj.name + " : " + obj.age);	   
    }
}

function callback1(){
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var str = xmlHttp.responseText;
        var obj = eval("(" + str + ")");
        //alert(obj.name + " : " + obj.age);	 
        //alert("123");
        var first ="";
        var second ="";
        var third ="";
        var fourth ="";
        for(var i=0;i<obj.length;i++){
        	if(obj[i].group_id==1)
        		first = first+obj[i].num+"  ";
        	else if(obj[i].group_id==2)
        		second = second+obj[i].num+"  ";
        	else if(obj[i].group_id==3)
        		third = third+obj[i].num+"  ";
        	else 
        		fourth = fourth +obj[i].num+"  ";
        }
        Dialog.alert("第一组："+first + "第二组："+ second+ "第三组："+third +"第四组："+fourth);
    }
}

function fenzu(){
	//alert("view_result");
	var maxnumbers = document.lotto.maxnum.value*1;
	//alert(maxnumbers);
	sendRequest("GET","fenzu.action?maxnumbers="+maxnumbers,true,callback);
}

function first(){
	sendRequest("GET","fenzu_view.action?huodong_id="+1,true,callback1);
}

function second(){
	sendRequest("GET","fenzu_view.action?huodong_id="+2,true,callback1);
}

function third(){
	sendRequest("GET","fenzu_view.action?huodong_id="+3,true,callback1);
}

function delete_fenzu(){
	sendRequest("GET","delete_fenzu.action",true,callback2);
}

function callback2(){
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var str = xmlHttp.responseText;
        var obj = eval("(" + str + ")");
        Dialog.alert(obj.name + " : " + obj.age);
    }
}

function delete_confirm() {  
    var msg = "确认删除已经存在的分组数据吗？？？";  
    if (confirm(msg) == true) {  
    	delete_fenzu();  
    } else {  
        return false;  
    }  
}  
</script>
</head>
<body align="center">
<form name="lotto">
总人数<input type="text" name="maxnum" value="80"><a href="#" onclick="delete_confirm();return false;">删除已存在分组方案</a><br />
<br/>
<a href="#" onclick="fenzu();return false;">生成分组方案</a><br /><br />
<a href="#" onclick="first();return false;">获取第一次活动分组方案</a><br /><br />
<a href="#" onclick="second();return false;">获取第二次活动分组方案</a><br /><br />
<a href="#" onclick="third();return false;">获取第三次活动分组方案</a><br /><br />
</form>
</body>
</html>